//
//  ViewController.m
//  11106
//
//  Created by student on 16/3/1.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIScrollViewDelegate>

@property (nonatomic,strong) UIScrollView *scrollView;
@property (nonatomic,strong) UIPageControl *pageControl;


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.scrollView = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    // 获取屏幕宽度高度
    CGFloat w = self.scrollView.bounds.size.width;
    CGFloat h = self.scrollView.bounds.size.height;
    
    // 添加图片
    for (int i=0;i<4;i++)
    {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(w*i, 0, w, h)];
        [imageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"guide%i",i]]];
        [self.scrollView addSubview:imageView];
    }
    
    // 设置滑动条尺寸
    self.scrollView.contentSize = CGSizeMake(w*4, 0);
    // 分页
    self.scrollView.pagingEnabled = YES;
    // 横向不显示
    self.scrollView.showsHorizontalScrollIndicator = NO;
    
    
    // 添加代理
    self.scrollView.delegate = self;
    // 添加pageControl
    self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(141,456,39,37)];
    // 设置有几页
    self.pageControl.numberOfPages = 4;
    // 设置当前显示哪一页
    self.pageControl.currentPage = 0;
    // 设置颜色
    self.pageControl.pageIndicatorTintColor = [UIColor yellowColor];
    self.pageControl.currentPageIndicatorTintColor = [UIColor redColor];
    
    // 添加滑动条到视图
    [self.view addSubview:self.scrollView];
    [self.view addSubview:self.pageControl];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    self.pageControl.currentPage = scrollView.contentOffset.x/self.scrollView.bounds.size.width;
}

@end
